package com.jeewms.www.tms;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.GridView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.jeewms.www.tms.base.BaseActivity;
import com.jeewms.www.tms.bean.bean.HomeBtnBean;
import com.jeewms.www.tms.constance.Constance;
import com.jeewms.www.tms.ui.adapter.HomeGridAdapter;
import com.jeewms.www.tms.util.BannerUtil;
import com.jeewms.www.tms.util.SharedPreferencesUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 13799 on 2018/7/2.
 */

public class HomeActivity2 extends BaseActivity {

    HomeGridAdapter adapter;
    HomeGridAdapter adapterTop;
    GridView gvHome;
    GridView gvHomeTop;
    ArrayList<HomeBtnBean> list = new ArrayList<>();
    ArrayList<HomeBtnBean> listTop = new ArrayList<>();
    List<String> bannerList = new ArrayList<>();
    @BindView(R.id.convenientBanner)
    ConvenientBanner convenientBanner;

    public static void show(Context context) {
        Intent intent = new Intent(context, HomeActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_home);
        ButterKnife.bind(this);
        init();
        setBanner();
    }

    private void init() {
        findViewById(R.id.btn_titlebar_right).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferencesUtil.getInstance(HomeActivity2.this).setKeyValue(Constance.SHAREP.PASSWORD, "");
                LoginActivity.show(HomeActivity2.this);
                finish();
            }
        });
        adapter = new HomeGridAdapter();
        adapterTop = new HomeGridAdapter();
        gvHome = findViewById(R.id.gv_home);
        gvHome.setAdapter(adapter);
        gvHomeTop = findViewById(R.id.gv_home_top);
        gvHomeTop.setAdapter(adapterTop);
        adapterTop.setType(1);
        addBtn();

    }

    //添加按钮
    private void addBtn() {
        list.clear();
//        for (int i = 0; i < Constance.btnNameList.length; i++) {
//            addBtn2List(Constance.btnNameList[i], Constance.btnImgList[i]);
//        }
//        list.add(new HomeBtnBean("", 0));
//        list.add(new HomeBtnBean("", 0));
//        adapter.setList(list);
//        adapter.notifyDataSetChanged();
//        listTop.clear();
//        listTop.add(new HomeBtnBean("扫码查询", R.drawable.shouye_saomachaxun));
//        listTop.add(new HomeBtnBean("任务清单", R.drawable.shouye_renwuqingdan));
//        listTop.add(new HomeBtnBean("我的统计", R.drawable.shouye_wodetongji));
//        listTop.add(new HomeBtnBean("更多", R.drawable.shouye_gengduo));
        adapterTop.setList(listTop);
        adapterTop.notifyDataSetChanged();
    }

    private void addBtn2List(String btnName, int imgResId) {
//        HomeBtnBean btn1 = new HomeBtnBean(btnName,imgResId);
//        list.add(btn1);
    }

    public void setBanner() {
    //    bannerList.add("http://218.5.177.99/zzwms/images/app/home1.jpg");
        bannerList.add("http://192.168.200.100/zzwms/images/app/home2.jpg");
    //    bannerList.add("http://218.5.177.99/zzwms/images/app/home3.jpg");
        BannerUtil.showBanner(convenientBanner, bannerList);
    }
}
